package com.tour.tour.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tour.tour.common.Response;
import com.tour.tour.entity.Spot;
import com.tour.tour.mapper.SpotMapper;
import com.tour.tour.service.SpotService;
import com.tour.tour.utils.constant.SystemConstants;
import com.tour.tour.vo.SpotVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author YounGCY
 * @date 2023-5-16 上午 3:01
 * @description
 */
@Slf4j
@Service
public class SpotServiceImpl extends ServiceImpl<SpotMapper, Spot> implements SpotService {
    
    @Override
    public Response<List<SpotVO>> getPage(Integer current) {
        Page<Spot> page = query()
                .page(new Page<>(current, SystemConstants.MAX_PAGE_SIZE));
        // 获取当前页数据
        List<Spot> records = page.getRecords();
        List<SpotVO> vos = new ArrayList<>();
        for (Spot record : records) {
            SpotVO vo = toSpotVO(record);
            vos.add(vo);
        }
        return Response.success(vos);
    }
    
    private SpotVO toSpotVO(Spot spot) {
        return new SpotVO(spot);
    }
    
}
